var tools = require('../utils/tools.js');
var mongo = require('../routes/mongoosenew.js');
var schame = {
    //昵称
    nickname: {
        type: String,
        required: true
    },
    //openid
    openid: {
        unique: true,
        type: String,
        required: true
    },
    likeMan: String,
    date: {
        type: Date,
        default: new Date()
    }
};
module.exports.config = function(appname) {
    this.Model = mongo(appname + '_vote', schame, appname + '_vote').model;
    return this;
}
module.exports.save = function(user, _callback) {
    this.Model.update({ "openid": user.openid }, { $set: user }, {
        upsert: true,
        overwrite: true
    }, function(err) {
        tools.execCB(_callback, err);
    });
}
module.exports.findByLikeMan = function(lineman, cb) {
    this.Model.find({ likeMan: lineman }, function(err, result) {
        tools.execCB(cb, err, {result:result});
    });
}